package com.medical.admin.hospital.controller;

import com.medical.admin.hospital.common.dto.HealthyEssayDto;
import com.medical.admin.hospital.common.vo.HealthyEssayVo;
import com.medical.admin.hospital.common.vo.PageVo;
import com.medical.admin.hospital.service.HealthyEssayService;
import com.qf.medical.ex.BaseException;
import com.qf.medical.response.ResponseCode;
import com.qf.medical.response.ResponseEntity;
import com.qf.medical.up.aliyun.AliOSSUtilsAutoConfiguration;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.io.IOException;
/**
 * @description: 健康百科信息管理
 * @author: LuAn
 * @date: 2024/4/27
 */
@Api(tags = "健康百科管理Api在线文档")
@RestController
@RequestMapping("/healthyEssay")
public class HealthyEssayController {
    @Resource
    private HealthyEssayService healthyEssayService;

    @Resource
    private AliOSSUtilsAutoConfiguration aliOSSUtilsAutoConfiguration;

    @GetMapping("/page")
    @ApiOperation("动态分页查询健康百科信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "healthyEssayTitle", value = "健康百科标题"),
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "页大小")})
    public ResponseEntity<PageVo<HealthyEssayVo>> list(String healthyEssayTitle, @RequestParam(defaultValue = "1")
    int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.success(healthyEssayService.list(healthyEssayTitle,pageNum,pageSize));
    }

    @ApiOperation("新增健康百科信息")
    @PostMapping("/add")
    @ApiImplicitParam(name = "healthyEssayDto" ,value = "健康百科信息")
    public ResponseEntity<Integer> add(@RequestBody HealthyEssayDto healthyEssayDto){
        return ResponseEntity.success(healthyEssayService.insert(healthyEssayDto));
    }

    @ApiOperation("修改健康百科信息")
    @PutMapping("/modify")
    @ApiImplicitParam(name = "healthyEssayDto" ,value = "医院信息")
    public ResponseEntity<Integer> modify(@RequestBody HealthyEssayDto healthyEssayDto){
        return ResponseEntity.success(healthyEssayService.update(healthyEssayDto));
    }

    @ApiOperation("删除健康百科信息")
    @DeleteMapping("/remove")
    @ApiImplicitParam(name = "healthyEssayId" ,value = "医院ID")
    public ResponseEntity<Integer> remove(@NotNull Long healthyEssayId){
        return ResponseEntity.success(healthyEssayService.delete(healthyEssayId));
    }

    @ApiOperation("查询健康百科信息详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "healthyEssayId" ,value = "医院ID")
    public ResponseEntity<HealthyEssayVo> detail(@NotNull Long healthyEssayId){
        return ResponseEntity.success(healthyEssayService.select(healthyEssayId));
    }

    @ApiOperation("健康百科缩略图")
    @PostMapping("/upload")
    @ApiImplicitParam(name = "file",value = "缩略图文件对象")
    public String upload(@NotNull MultipartFile file){
        try {
            return aliOSSUtilsAutoConfiguration.upload(file);
        } catch (IOException e) {
            throw new BaseException(ResponseCode.SYS_ERROR);
        }
    }
}
